from app import db
import os
from werkzeug.security import generate_password_hash, check_password_hash


class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(64), index=True, unique=True)
    password_hash = db.Column(db.String(120), index=True, unique=True)
    email_address = db.Column(db.String(140))
    last_seen = db.Column(db.DateTime)

    @property
    def password(self):
        raise AttributeError('password is not a readable attribute')

    @password.setter
    def set_password(self, password):
        self.password_hash = generate_password_hash(password)
        return self.password_hash

    def verify_password(self, password):
        return check_password_hash(self.password_hash, password)

    is_authenticated = True
    is_active = True
    is_anonymous = False

    def get_id(self):
        return str(self.id)

    def avatar(self, size):
        return '/app/static/images/2.jpg'

    def __repr__(self):
        return '%r' % self.id


class Product(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    server_name = db.Column(db.String(64), index=True, unique=True)
    vmware_name = db.Column(db.String(240))
    server_type = db.Column(db.String(120))
    server_address = db.Column(db.String(140))
    server_port = db.Column(db.Integer)
    creat_date = db.Column(db.String(120))
    creat_person = db.Column(db.String(120))
    server_user = db.Column(db.String(64))
    server_password = db.Column(db.String(120))
    edit_date = db.Column(db.String(120))
    edit_person = db.Column(db.String(120))
    remark = db.Column(db.String(2400))
    group = db.Column(db.String(240))
    members = db.Column(db.String(2400))
    databese = db.Column(db.String(240))
    server_config = db.Column(db.String(2400))

    def __repr__(self):
        return '%r' % self.server_name


class Group(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    big_group = db.Column(db.String(240))
    small_group = db.Column(db.String(240))
    members = db.Column(db.String(2400))

    def __repr__(self):
        return '%r' % self.small_group


class Acctproduct(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    server_name = db.Column(db.String(64), index=True)
    server_address = db.Column(db.String(140))
    server_owner_id = db.Column(db.Integer)

    def __repr__(self):
        return '%r' % self.server_name


class Applyinfo(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    server_name = db.Column(db.String(64), index=True)
    apply_user = db.Column(db.String(120))
    apply_date = db.Column(db.String(120))
    apply_status = db.Column(db.Integer)
    approve_date = db.Column(db.String(120))
    apply_userid = db.Column(db.Integer)
    execute_user = db.Column(db.String(120))
    remark = db.Column(db.String(120))

    def __repr__(self):
        return '%r' % self.server_name


class Updateturn(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    output = db.Column(db.String(120))
    up_version = db.Column(db.String(64))
    en_product = db.Column(db.String(120))
    up_host = db.Column(db.String(120))
    update_way = db.Column(db.Integer)
    begin_date = db.Column(db.String(120))
    use_time = db.Column(db.Integer)
    up_status = db.Column(db.Integer)
    up_persion = db.Column(db.String(120))
    remark = db.Column(db.String(2400))
    progress = db.Column(db.String(240))

    def __repr__(self):
        return '%r' % self.id


class Updatejour(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    output = db.Column(db.String(120))
    read_status = db.Column(db.Integer)
    update_date = db.Column(db.Integer)
    update_time = db.Column(db.String(120))
    message = db.Column(db.String(2400))
    up_persion = db.Column(db.String(120))
    log_path = db.Column(db.String(120))

    def __repr__(self):
        return '%r' % self.id


class Updatepath(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    path_type = db.Column(db.Integer)
    path_ip = db.Column(db.String(240))
    path_port = db.Column(db.Integer)
    get_path = db.Column(db.String(240))
    to_path = db.Column(db.String(240))
    server_ip = db.Column(db.String(240))
    path_user = db.Column(db.String(120))
    path_password = db.Column(db.String(120))
    path_name = db.Column(db.String(240))

    def __repr__(self):
        return '%r' % self.id


class Bopupdateturn(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    bop_ip = db.Column(db.String(120))
    bop_path = db.Column(db.String(240))
    up_status = db.Column(db.Integer)
    bop_war = db.Column(db.String(480))
    up_persion = db.Column(db.String(240))
    path_name = db.Column(db.String(240))
    to_path_name = db.Column(db.String(240))

    def __repr__(self):
        return '%r' % self.id


class UFTupdateturn(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    output = db.Column(db.String(120))
    up_version = db.Column(db.String(64))
    en_product = db.Column(db.String(120))
    up_host = db.Column(db.String(120))
    update_way = db.Column(db.Integer)
    begin_date = db.Column(db.String(120))
    use_time = db.Column(db.Integer)
    up_status = db.Column(db.Integer)
    up_persion = db.Column(db.String(120))
    remark = db.Column(db.String(2400))
    progress = db.Column(db.String(240))

    def __repr__(self):
        return '%r' % self.id
